// Achievement by G3X / GeXeH - Enjoy
// Version 1.0

// Achievement: Get into the top 5 zombies list.
local total = achievements.GetValue( "Zombie Survival: Hoard Leader", "total", 0 )
if ( achievements.IsGamemode( "Zombie Survival" ) || total == 5 ) then

	local function RcTopZombies( msg )
		local indexx = msg:ReadShort()
		local zombie = msg:ReadString()
		
		for i = string.len( zombie ), 1, -1 do
			if ( string.sub( zombie, i, i ) == " " ) then
				local zombieName = string.Left( zombie, i - 2 )
					if ( LocalPlayer():Name() == zombieName && total != 5 ) then
						total = math.Clamp( total + 1, 0, 5 )
						achievements.Update( "Zombie Survival: Hoard Leader", total / 5, total .. "/5" )
						achievements.SetValue( "Zombie Survival: Hoard Leader", "total", total )
					end
			break
		end
		
end

		return indexx, zombie
	end
	
	usermessage.AddHook( "RcTopZombies", "Achievements.Zombie Survival:HoardLeader", RcTopZombies )
	
	achievements.Register( "Zombie Survival: Hoard Leader", "Get into the top 5 zombies list 5 times.", "achievements/zs_hoardleader", total / 5, total .. "/5" )
	
end